<template>
  <view class="login">
    <view class="login-title" @tap="handleTest">登录</view>
    <view class="tab">
      <view :class="type===1?'tab-c':''" @tap="type=1">账号密码登录</view>
      <view :class="type===0?'tab-c':''" @tap="handleJoin">商家入驻</view>
    </view>
    <view class="input" v-if="type===1">
      <view class="input-title">账号</view>
      <input type="text" v-model="phone" placeholder="输入账号" />
    </view>
    <view class="input" v-if="type===1">
      <view class="input-title">密码</view>
      <input type="password" v-model="pwd" placeholder="输入密码" />
    </view>
    <view class="forgive" @tap="handleForgive">忘记密码?</view>
    <view class="input" v-if="type===0">
      <view class="input-title">手机号</view>
      <input type="number" v-model="phone" placeholder="输入手机号" />
    </view>
    <view class="input" v-if="type===0">
      <view class="input-title">验证码</view>
      <input type="number" v-model="code" placeholder="输入验证码" />
      <view class="input-getCore">获取验证码</view>
    </view>
    <button class="submit" @tap="handleLogin">登录</button>
    <view class="btm">
      还未注册 ?
      <span @tap.stop="handleJoin">立即注册</span>
    </view>
  </view>
</template>

<script>
import { login } from './api'
import { saveTokenid } from '@/src/basic/utils/user';
import { getStoreInformation } from '../my/api'
import CONSTS from '@/src/consts';
export default {
  data () {
    return {
      res: {},
      type: 1,
      pwd: '',
      phone: '',
      code: ''
    }
  },
  onLoad (option) {

  },
  methods: {
    handleJoin () {
      //return this.$utils.common.navigateTo('src/pages/join/index')
	  this.$utils.common.navigateTo('src/pages/register/register?id=1')
    },
    handleForgive () {
      return this.$utils.common.navigateTo('src/pages/login/forgive')

    },
    handleRegister (url) {
      if (url) {
        let params = {
          url: true
        }
        return this.$utils.common.navigateTo('src/pages/register/index', params)
      }
      this.$utils.common.navigateTo('src/pages/register/index')
    },
    handleTest () {
      this.phone = '17178868109'
      // this.phone = '18757436548'
      this.pwd = '883721'
    },
    handleCheckStatus (toExamine, token, typeId) {
      if (toExamine === 0) {
        // window.location.href='/merchant-entry-h5/html/life-circle/step-1.html'
        //window.location.href = `https://www.hailu1688.com/merchant-entry-h5/html/life-circle/step-1.html?token=${token}&typeId=${typeId}`
		console.log(`https://www.hailu1688.com/merchant-entry-h5/html/life-circle/step-1.html?token=${token}&typeId=${typeId}`)
        return this.$utils.common.navigateTo('src/pages/register/step')
      }
      // return this.$utils.common.switchTab('src/pages/index/index') //旧版
	  return this.$utils.common.navigateTo('src/pages/ports/index') // 新版
    },
    async handleLogin () {
      this.$loading()
      const param = {
        account: this.phone,
        loginType: 1,
        pwd: this.pwd
      }
      try {
        const { data: userInfo } = await login(param);
        this.$utils.user.saveUserInfo(userInfo)
        saveTokenid(userInfo.accessToken)
        const { data } = await getStoreInformation()
		
		uni.setStorageSync('userInfo', userInfo)
        uni.setStorageSync('shopInfo', data);

        setTimeout(() => {
          this.$hideLoading()

          this.handleCheckStatus(userInfo.toExamine, userInfo.accessToken, userInfo.firstManagementTypeId)
        }, 1500)
      } catch (err) {
        if (err.code !== 200) {
          return this.$utils.common.toast.fail(err.data.message);
        }
      }
    }
  }
}
</script>

<style scope lang="scss">
.forgive {
  text-align: right;
  padding-top: 42rpx;
  font-size: 30rpx;
  font-family: PingFang SC;
  font-weight: 400;
  line-height: 40rpx;
  color: rgba(196, 203, 213, 1);
  opacity: 1;
}
.login {
  background-color: #ffffff;
  height: 100vh;
  padding: 164rpx 64rpx;
  &-title {
    font-size: 80rpx;
    font-family: PingFang SC;
    font-weight: 600;
    line-height: 106rpx;
    color: rgba(46, 62, 83, 1);
    opacity: 1;
  }
  .btm {
    position: fixed;
    left: 0;
    bottom: 128rpx;
    width: 100vw;
    text-align: center;
    font-size: 30rpx;
    font-family: PingFang SC;
    font-weight: 400;
    line-height: 40px;
    color: #c4cbd5;
    span {
      color: #0cd4d3 !important;
    }
  }
  .submit {
    margin-top: 170rpx;
    width: 624rpx;
    height: 88rpx;
    background: rgba(12, 212, 211, 1);
    opacity: 1;
    border-radius: 88rpx;
    font-size: 34rpx;
    font-family: PingFang SC;
    font-weight: 400;

    color: rgba(255, 255, 255, 1);
  }
  .input {
    display: flex;
    padding-top: 70rpx;
    padding-bottom: 50rpx;
    border-bottom: 2rpx solid rgba(227, 227, 227, 1);
    &-title {
      padding-right: 60rpx;
      font-size: 30rpx;
      font-family: PingFang SC;
      font-weight: 400;
      line-height: 40rpx;
      color: rgba(46, 62, 83, 1);
      white-space: nowrap;
    }

    input::placeholder,
    &-getCore {
      white-space: nowrap;
      font-size: 30rpx;
      font-family: PingFang SC;
      font-weight: 400;
      line-height: 40rpx;
      color: rgba(196, 203, 213, 1);
    }
  }
  .tab {
    display: flex;
    align-items: center;
    padding-top: 40rpx;
    padding-bottom: 100rpx;

    &-c {
      font-size: 28rpx;
      font-family: PingFang SC;
      font-weight: 400;
      line-height: 38rpx;
      color: rgba(46, 62, 83, 1) !important;
    }
    view {
      transition: all 0.5s;
      line-height: 40rpx;
      padding: 0 54rpx;
      font-size: 28rpx;
      font-family: PingFang SC;
      font-weight: 400;
      line-height: 38rpx;
      color: rgba(196, 203, 213, 1);
      opacity: 1;
    }
    view:nth-child(1) {
      padding-left: 0;
      border-right: 2rpx solid rgba(112, 112, 112, 1);
    }
  }
}
</style>
